﻿# encoding:utf-8
# 基础模块
import os

# 代表当前登录的用户
g_curBot = None

def setBot(bot):
    global g_curBot
    g_curBot = bot

def getBot():
    return g_curBot

# 判断当前用户是否是群
def isGroup(user):
    if user is None:
        print('isGrou user empty')
        return False

    return 'Group'==str(user)[1:6]

# 判断 user 是否是当前登录的用户
def isCurUser(user):
    if not hasattr(user, 'puid'):
        return False
    
    return getBot().self.puid==user.puid

# 判断当前用户是否是公众号
def isMp(user):
    if user is None:
        print('isMp user empty')
        return False

    return '<MP:'==str(user)[0:4]

# 消息类型枚举
class msgType():
    # 文本
    TEXT = 'Text'
    # 位置
    MAP = 'Map'
    # 名片
    CARD = 'Card'
    # 提示
    NOTE = 'Note'
    # 分享
    SHARING = 'Sharing'
    # 图片
    PICTURE = 'Picture'
    # 语音
    RECORDING = 'Recording'
    # 文件
    ATTACHMENT = 'Attachment'
    # 视频
    VIDEO = 'Video'
    # 好友请求
    FRIENDS = 'Friends'
    # 系统
    SYSTEM = 'System'

# 获取临时文件夹路径
def getTmpFilePath(fileName=None):
    tmp = 'tmp'
    try:
        # 创建目录
        os.mkdir(tmp)
    except:
        # 路径存在会报错
        pass
    
    fullPath = tmp
    if fileName is not None:
        fullPath = fullPath + os.sep + fileName

    return fullPath

# 获取临时图片存储路径
# subDirName tmp 文件夹下子文件夹名，不能为空
# fileName 文件夹下真正文件名
def getTmpFilePathSub(subDirName, fileName=None):
    if not subDirName:
        print('getTmpFilePathSu subDirName empty')
        return ''

    path = getTmpFilePath() + os.sep + subDirName
    try:
        # 创建目录
        os.mkdir(path)
    except:
        # 路径存在会报错
        pass

    if fileName is not None:
        path = path + os.sep + fileName

    return path

# 获取临时图片存储路径
def getTmpImgPath(fileName=None):
    return getTmpFilePathSub('pic', fileName)
    
# 获取日志存储路径
def getTmpLogPath(fileName=None):
    return getTmpFilePathSub('log', fileName)